//
//  AppDelegate+LaunchSetting.m
//  OCFrame
//
//  Created by hfzhangzhang on 2017/3/21.
//  Copyright © 2017年 hfzhangzhang. All rights reserved.
//

#import "AppDelegate+LaunchSetting.h"
#import "SplashViewController.h"

@implementation AppDelegate (LaunchSetting)

- (void)launchSetting{
    //1.广告页
    //[self dimissLaunchScreenDelay:3.];
    [self dimissLaunchImageDelay:3.];
    //2.引导页
    [SplashViewController showSplashIfNeeded];
}

/**
 LaunchImage 广告位延时
 @param delay 启动消失时间
 */
- (void)dimissLaunchImageDelay:(float)delay;
{
    NSArray *imagesDict = [[NSBundle mainBundle] infoDictionary][@"UILaunchImages"];
    CGSize viewSize = [UIScreen mainScreen].bounds.size;
    NSString *viewOrientation = @"Portrait"; //横屏请设置成 @"Landscape"
    NSString *launchImageName = nil;
    for (NSDictionary *dict in imagesDict) {
        if (CGSizeEqualToSize(CGSizeFromString(dict[@"UILaunchImageSize"]), viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
            launchImageName = dict[@"UILaunchImageName"];
        }
    }
    UIImageView *launchView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:launchImageName]];
    launchView.userInteractionEnabled = YES;
    launchView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [launchView setFrame:[[UIScreen mainScreen] bounds]];
    [self.window addSubview:launchView];
    
    [UIView animateWithDuration:1 delay:delay options:UIViewAnimationOptionCurveEaseIn animations:^{
        launchView.alpha = 0;
        launchView.transform = CGAffineTransformMakeScale(2, 2);
    } completion:^(BOOL finished) {
        [launchView removeFromSuperview];
    }];
}

/**
 LaunchScreen 广告位延时
 @param delay 启动消失时间
 */

-(void)dimissLaunchScreenDelay:(float)delay{
    
    UIView *launchView = [[UIStoryboard storyboardWithName:[[NSBundle mainBundle] infoDictionary][@"UILaunchStoryboardName"] bundle:[NSBundle mainBundle]] instantiateInitialViewController].view;
    [self.window addSubview:launchView];
    
    [UIView animateWithDuration:2.0f delay:delay options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        launchView.alpha = 0.0f;
    } completion:^(BOOL finished) {
        [launchView removeFromSuperview];
    }];
}



@end
